﻿using System.IO;
using System.Net;
using System.Text;

namespace SimpleTFTP
{
    internal class Utilities
    {
        public static ushort ReadInt16(Stream stream)
        {
            BinaryReader br = new BinaryReader(stream);
            return (ushort)IPAddress.NetworkToHostOrder((short)br.ReadUInt16());
        }

        public static string ReadZString(Stream stream)
        {
            StringBuilder result = new StringBuilder();

            int c;
            while ((c = stream.ReadByte()) != 0)
            {
                result.Append((char)c);
            }

            return result.ToString();
        }
    }
}